<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp"%>
<title>用户登陆</title>
</head>
<body>
	<fieldset id="">
		<legend style="font-size: 25px; color: black">部门信息维护</legend>
		<div class="layui-form">
			<div class="layui-field-box">
				<!-- <form class="layui-form" > -->
				<div class="layui-form-item">
					<label class="layui-form-label">部门编号</label>
					<div class="layui-input-inline">
						<input type="text" name="code" placeholder="请输入编号"
							autocomplete="off" class="layui-input">
					</div>
					<label class="layui-form-label">部门名称</label>
					<div class="layui-input-inline">
						<input type="text" name="name" placeholder="请输入姓名"
							autocomplete="off" class="layui-input">
					</div>

					<input type="button" id="selc" value="搜索" lay-submit
						lay-filter="search" class="layui-btn" /> 
						<input onclick="openAdd()" type="button" value="添加" class="layui-btn"
						id="add1" />
				</div>

			</div>
			<input type="hidden" name="action" value="page"> <input
				type="hidden" name="pageIndex" value="1"> <input
				type="hidden" name="pageLimit" value="10">

		</div>
		<table style="" class=" layui-table">
			<thead>
				<tr>
					<th style="width: 15%; text-align: left;">ID</th>
					<th style="width: 15%; text-align: left;">部门编号</th>
					<th style="width: 15%; text-align: left;">部门名称</th>
					<th style="width: 15%; text-align: left;">部门电话</th>
					<th style="width: 15%; text-align: left;">部门人数</th>
					<th style="width: 20%; text-align: left;">操作</th>
				</tr>
			</thead>
			<tbody id="tbody">

			</tbody>
		</table>
		<div id="pageInfoDept" style="text-align: right; padding-right: 30px"></div>
	</fieldset>
	<script type="text/javascript">
			formSubmit("/DepartmentServlet","submit(search)","json",function(data){
				var curr = $("input[name='pageIndex']").val();
				var limit = $("input[name='pageLimit']").val();
				
				setPageInfo('pageInfoDept',data.count,curr,limit,function(obj,first){
					$("input[name='pageIndex']").val(obj.curr);
					$("input[name='pageLimit']").val(obj.limit);
					if(!first){
						refresh();
					}
				})
				
				var html="";
				$.each(data.list,function(i,every){
					var code = every.code?every.code:'';
					var name = every.name?every.name:'';
					var tel  = every.tel?every.tel:'';
					var count = every.count?every.count:'';
// 					console.log(every.count)
					var d={i:i+1,code:code,name:name,tel:tel,count:count}
					html += getlaytpl("#tradd2",d);
				})
				$("#tbody").html(html);
				layer.msg("查询成功")
			})
			refresh();
			function refresh(){
				$("input[value='搜索']").click();
			}
			
			function openAdd(){
				openlayer("/web/page/dept/add.jsp",refresh);
			}
			
			function del(code){
				layer.msg("删除成功");
				openConfirm(function(){
					ajax("/DepartmentServlet",{action:"del",code:code},"text",function(data){
						if(1==data){
							layer.msg("删除成功",refresh);
						}
					})
				})
			}
			
			function openUpd(code){
				openlayer("/web/page/dept/upd.jsp?code="+code,refresh)
			}
			
			
			
		</script>
	<script type="text/html" id="tradd2">
			<tr>
			<td>{{d.i}}</td>
			<td>{{d.code}}</td>
			<td>{{d.name}}</td>
			<td>{{d.tel}}</td>
			<td>{{d.count}}</td>
			<td>
				<a href='javascript:del("{{d.code}}");' 
					class="layui-btn layui-btn-sm layui-btn-danger">
					<i class="layui-icon layui-icon-delete"></i>
					</a>&nbsp;&nbsp;
					<input type="button" onclick='openUpd("{{d.code}}")' class="layui-btn layui-btn-sm" value="修改"/>
					
			</td>
		</tr>
		</script>

</body>
</html>
